 package net.go176.backpack.util;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import net.go176.backpack.util.simplenbt.Reflector;
import net.minecraft.entity.player.EntityPlayer;

 import org.bukkit.entity.Entity;
 import org.bukkit.inventory.Inventory;
 import org.bukkit.inventory.ItemStack;
 
 
 
 
 public class NMSUtil
 {
   private static boolean isMCPServer = false;
   private static Method getNMSInventory = null;
   private static Method asNMSCopy = null;
   private static Method asCraftMirror = null;
   private static Constructor<?> newCraftInventory = null;
   private static Field itemsInventoryCustom = null;
   private static Field itemsInventoryPlayer = null;
   private static Field itemsInventoryBasic = null;
 
 
 
   
   private static Method resetPlayerEntity = null;
   private static Method clonePlayer = null;
   
   public static void init(String obcVersion, String coreVersion, boolean isMCPServer) throws ClassNotFoundException, NoSuchMethodException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
     NMSUtil.isMCPServer = isMCPServer;
     String obc = "org.bukkit.craftbukkit." + obcVersion;
     String[] split = obcVersion.substring(1).split("_");
     int ver1 = Integer.parseInt(split[0]);
     int ver2 = Integer.parseInt(split[1]);
     InvTrans.legacy = (ver1 == 1 && ver2 <= 8);
     
     Class<?> clazzCraftInventory = Class.forName(String.valueOf(obc) + ".inventory.CraftInventory");
     getNMSInventory = clazzCraftInventory.getDeclaredMethod("getInventory", new Class[0]);
     getNMSInventory.setAccessible(true);
     
     Class<?> clazzCraftItemStack = Class.forName(String.valueOf(obc) + ".inventory.CraftItemStack");
     asNMSCopy = clazzCraftItemStack.getDeclaredMethod("asNMSCopy", new Class[] { ItemStack.class }); byte b; int i; Method[] arrayOfMethod;
     for (i = (arrayOfMethod = clazzCraftItemStack.getDeclaredMethods()).length, b = 0; b < i; ) { Method m = arrayOfMethod[b];
       if (m.getName().equals("asCraftMirror")) {
         asCraftMirror = m;
         break;
       } 
       b++; }
     
     newCraftInventory = clazzCraftInventory.getConstructors()[0];
     
     Class<?> clazzCraftInventoryCustom = Class.forName(String.valueOf(obc) + ".inventory.CraftInventoryCustom$MinecraftInventory");
     itemsInventoryCustom = clazzCraftInventoryCustom.getDeclaredField("items");
     itemsInventoryCustom.setAccessible(true);
     
     Class<?> clazzInventoryPlayer = Class.forName("net.minecraft." + (isMCPServer ? "entity.player.InventoryPlayer" : ("server." + coreVersion + ".PlayerInventory")));
     itemsInventoryPlayer = clazzInventoryPlayer.getDeclaredField(isMCPServer ? "field_70462_a" : "items");
     
     Class<?> clazzInventoryBasic = Class.forName("net.minecraft." + (isMCPServer ? "inventory.InventoryBasic" : ("server." + coreVersion + ".InventorySubcontainer")));
     itemsInventoryBasic = clazzInventoryBasic.getDeclaredField(isMCPServer ? "field_70482_c" : "items");
     itemsInventoryBasic.setAccessible(true);
 
 
 
 
 
 
 
 
 
 
 
 
 
     
     if (isMCPServer) {
       Class<?> clazzEntityPlayerMP = Class.forName("net.minecraft.entity.player.EntityPlayerMP");
       clonePlayer = clazzEntityPlayerMP.getDeclaredMethod("func_71049_a", new Class[] { EntityPlayer.class, boolean.class });
     } else {
       Class<?> clazzEntityPlayer = Class.forName("net.minecraft.server." + coreVersion + ".EntityPlayer");
       resetPlayerEntity = clazzEntityPlayer.getDeclaredMethod("reset", new Class[0]);
     } 
   }
   
   public static Object getNMSEntity(Entity entity) {
     return Reflector.getNMSEntity(entity);
   }
   
   public static Object getNMSInventory(Inventory inv) {
     try {
       return getNMSInventory.invoke(inv, new Object[0]);
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static void setItemsFromInventoryPlayer(Object inv, Object invPlayer) {
     try {
       itemsInventoryCustom.set(inv, itemsInventoryPlayer.get(invPlayer));
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static void setItemsFromInventoryBasic(Object inv, Object invBasic) {
     try {
       itemsInventoryCustom.set(inv, itemsInventoryBasic.get(invBasic));
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static Object asNMSCopy(ItemStack itemstack) {
     try {
       return asNMSCopy.invoke((Object)null, new Object[] { itemstack });
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static ItemStack asCraftMirror(Object itemstack) {
     try {
       return (ItemStack)asCraftMirror.invoke((Object)null, new Object[] { itemstack });
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static Inventory getBukkitInventory(Object iInventory) {
     try {
       return (Inventory)newCraftInventory.newInstance(new Object[] { iInventory });
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
 
 
 
 
 
 
 
 
 
 
   
   public static void resetPlayerEntity(Object entityPlayer) {
     try {
       if (isMCPServer)
       { clonePlayer.invoke(entityPlayer, new Object[] { MCPUtil.newFakePlayer(entityPlayer), Boolean.valueOf(true) }); }
       else
       { resetPlayerEntity.invoke(entityPlayer, new Object[0]); } 
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
 }


/* Location:              D:\User\Xuan\Downloads\MyBackpack1.2.5.jar!\net\saralab\mybackpac\\util\NMSUtil.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.1.3
 */